﻿package net.pezzato.grpbannr{
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.net.URLRequest;
	import flash.events.Event;
	public class PhotoSliderElement extends Sprite {
		public static const PHOTO_LOADED:String = "photo loaded in PhotoSliderElement";
		private var maxWidth_:Number;
		private var maxHeight_:Number;
		private var photo_:Loader;
		public function PhotoSliderElement(maxWidth:Number = 100, maxHeight:Number = 100){
			maxWidth_ = maxWidth;
			maxHeight_ = maxHeight;
		}
		public function loadFromUrl(url:String) {
			photo_ = new Loader();
			photo_.contentLoaderInfo.addEventListener(Event.COMPLETE, onPhotoLoaded);
			photo_.load(new URLRequest(url));
		}
		public function onPhotoLoaded(event:Event) {
			addChild(photo_);
			drawBorders();
			dispatchEvent(new Event(PHOTO_LOADED));
		}
		private function drawBorders() {
			graphics.lineStyle(4, 0x000000, 1, true);
			graphics.drawRoundRect(0, 0, photo_.width, photo_.height, 2, 2);
		}
	}
}